package com.zhuo.project.k3.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zhuo.common.utils.SecurityUtils;
import com.zhuo.common.utils.poi.ExcelUtil;
import com.zhuo.framework.aspectj.lang.annotation.Log;
import com.zhuo.framework.aspectj.lang.enums.BusinessType;
import com.zhuo.framework.web.controller.BaseController;
import com.zhuo.framework.web.domain.AjaxResult;
import com.zhuo.framework.web.page.TableDataInfo;
import com.zhuo.project.k3.domain.ZzDepartment;
import com.zhuo.project.k3.service.IZzDepartmentService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * 卓正部门信息Controller
 * 
 * @author ruoyi
 * @date 2020-03-18
 */
@Api("部门主数据同步管理")
@RestController
@RequestMapping("/k3/department")
public class ZzDepartmentController extends BaseController
{
    @Autowired
    private IZzDepartmentService zzDepartmentService;

    /**
     * 查询卓正部门信息列表
     */
    @PreAuthorize("@ss.hasPermi('k3:department:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZzDepartment zzDepartment)
    {
        startPage();
        List<ZzDepartment> list = zzDepartmentService.selectZzDepartmentList(zzDepartment);
        return getDataTable(list);
    }

    /**
     * 导出卓正部门信息列表
     */
    @PreAuthorize("@ss.hasPermi('k3:department:export')")
    @Log(title = "卓正部门信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ZzDepartment zzDepartment)
    {
        List<ZzDepartment> list = zzDepartmentService.selectZzDepartmentList(zzDepartment);
        ExcelUtil<ZzDepartment> util = new ExcelUtil<ZzDepartment>(ZzDepartment.class);
        return util.exportExcel(list, "department");
    }

    /**
     * 获取卓正部门信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('k3:department:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(zzDepartmentService.selectZzDepartmentById(id));
    }

    /**
     * 新增卓正部门信息
     */
    @ApiOperation("同步部门主数据")
    @ApiImplicitParam(name = "zzDepartment", value = "同步部门主数据", dataType = "ZzDepartment")
    @PreAuthorize("@ss.hasPermi('k3:department:add')")
    @Log(title = "卓正部门信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZzDepartment zzDepartment)
    {
        return toAjax(zzDepartmentService.insertZzDepartment(zzDepartment));
    }

    /**
     * 修改卓正部门信息
     */
    @PreAuthorize("@ss.hasPermi('k3:department:edit')")
    @Log(title = "卓正部门信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZzDepartment zzDepartment)
    {
        return toAjax(zzDepartmentService.updateZzDepartment(zzDepartment));
    }

    /**
     * 删除卓正部门信息
     */
    @PreAuthorize("@ss.hasPermi('k3:department:remove')")
    @Log(title = "卓正部门信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zzDepartmentService.deleteZzDepartmentByIds(ids));
    }
}
